<?php
/**
 * 
 * @author Sasa Milojevic <milojevic.sasa@gmail.com>
 *
 */

class MY_Form_validation extends CI_Form_validation {

	public function __construct() {
		parent::__construct();
	}

	public function is_unique($str, $field, $id=NULL) {
		$field_ar = explode('.', $field);
		//$query = $this->CI->db->get_where($field_ar[0], array($field_ar[1] => $str), 1, 0);
		$sql = "SELECT id FROM {$field_ar[0]} WHERE {$field_ar[1]} = '{$str}' ";
		
		if(isset($id)) $sql .= " AND id <> {$id} ";
		
		$query = $this->CI->db->query($sql);
		if ($query->num_rows() === 0) {
			return TRUE;
		}

		return FALSE;
	}
}